package com.zhupanlin.sqlSession;

import com.zhupanlin.config.XMLConfigBuilder;
import com.zhupanlin.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * 描述信息：
 *
 * @author zhupanlin
 * @version 1.0
 * @date 2025/2/8 17:15
 */
public class SqlSessionFactoryBuilder {
    
    public SqlSessionFactory build(InputStream is) throws DocumentException, PropertyVetoException {
        // 使用 dom4j 解析配置文件， 将解析出来的内容封装到 Configuration 中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(is);
        
        // 创建 SqlSessionFactory 对象
        DefaultSqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return sqlSessionFactory;
    }
    
}